package com.linkoog.devtools.action_test;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiParameter;
import com.intellij.util.indexing.FileBasedIndex;
import com.linkoog.devtools.type_index.ClassFieldIndex;
import org.jetbrains.annotations.NotNull;

public class MethodTestAction extends AnAction {

    @Override
    public void actionPerformed(@NotNull AnActionEvent event) {
        // 获取 PsiElement
        PsiElement element = event.getData(CommonDataKeys.PSI_ELEMENT);

        if (element instanceof PsiMethod) {
            PsiMethod psiMethod = (PsiMethod) element;
            // 当前选中的是一个方法
            String methodName = psiMethod.getName();
            System.out.println("Selected method: " + methodName);

            // 示例：获取方法的返回类型
            String returnType = psiMethod.getReturnType() != null ? psiMethod.getReturnType().getCanonicalText() : "void";
            System.out.println("Return type: " + returnType);

            // 示例：获取方法的参数信息
            for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) {
                System.out.println("Parameter: " + parameter.getName() + " Type: " + parameter.getType().getCanonicalText());
            }



        } else {
            // 当前选中元素不是一个方法
            System.out.println("Selected element is not a method.");
        }
    }

    @Override
    public void update(@NotNull AnActionEvent event) {
        // 获取 PsiElement
        PsiElement element = event.getData(CommonDataKeys.PSI_ELEMENT);

        // 设置动作的可用性
        boolean isMethod = element instanceof PsiMethod;
        event.getPresentation().setEnabledAndVisible(isMethod);
    }


}
